package com.amuse.amuse.controller;

import com.amuse.amuse.entity.PageBean;
import com.amuse.amuse.entity.ResponseData;
import com.amuse.amuse.entity.facilities;
import com.amuse.amuse.entity.facilityReservations;
import com.amuse.amuse.service.impl.FacilityPermissionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RestController
@CrossOrigin //跨域请求
@RequestMapping("/facility")
public class FacilityPermissionController extends BaseController{
    @Autowired
    private FacilityPermissionServiceImpl facilityPermissionService;

    /*
    * 场地添加
    * */
    @PostMapping("/addFacility")
    public ResponseData addFacility(facilities facilities){
        Integer integer = facilityPermissionService.addFacility(facilities);
        return resultBoolean(integer > 0);
    }

    /*
    *
    * 场地删除
    * */

    @PostMapping("/deleteFacility")
    public ResponseData deleteFacility(Integer facilityId){
        Integer integer = facilityPermissionService.deleteFacility(facilityId);
        return resultBoolean(integer > 0);
    }
    /*
    * 场地更新
    * */
    @PostMapping("/updateFacility")
    public ResponseData updateFacility(facilities facilities){
        Integer integer = facilityPermissionService.updateFacility(facilities);
        return resultBoolean(integer > 0);
    }

    /*
    * 场地查询
    * */
    @GetMapping("/findFacilityByTypeName")
    public ResponseData<PageBean<facilities>> findFacilityByTypeName(
             Integer pageNum,
             Integer pageSize,
            @RequestParam(required = false) String typeName
    ){
        return resultObj(facilityPermissionService.findFacilityByTypeName(pageNum, pageSize, typeName));
    }

    /*
    * 学生预约
    * */

    @PostMapping("/addFacilityReservations")
    public ResponseData addFacilityReservations(
            @RequestParam(required = false) Integer facilityId,
            @RequestParam(required = false) Integer studentId,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String reservationDate,
            @RequestParam(required = false) String status
    ){
        return resultBoolean(facilityPermissionService.addFacilityReservations(facilityId, studentId, startTime, endTime, reservationDate, status) > 0);
    }
    /*
    * 学生查看预约
    * */
    @GetMapping("/findFacilityReservations")
    public ResponseData<PageBean<facilityReservations>> findFacilityReservations(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer studentId
    ){
        return resultObj(facilityPermissionService.findFacilityReservations(pageNum, pageSize, studentId));
    }

    /*
    * 学生删除预约
    * */
    @PostMapping("/deleteFacilityReservations")
    public ResponseData deleteFacilityReservations(
            @RequestParam(required = false) Integer studentId,
            @RequestParam(required = false) Integer facilityId
    ){
        return resultBoolean(facilityPermissionService.deleteFacilityReservations(studentId, facilityId) > 0);
    }

    /*
    * 学生更新预约
    * */
    @PostMapping("/updateFacilityReservations")
    public ResponseData updateFacilityReservations(
            @RequestParam(required = false) Integer studentId,
            @RequestParam(required = false) Integer facilityId,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String reservationDate
    ){
        return resultBoolean(facilityPermissionService.updateFacilityReservations(studentId, facilityId, startTime, endTime, reservationDate) > 0);
    }




}
